package edu.nepu.flink.api.source;


import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.connector.kafka.source.KafkaSource;
import org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Date 2024/2/28 9:42
 * @Created by chenshuaijun
 */
public class MyKafkaSource {

    public static void main(String[] args) throws Exception {
        // 使用kafkaSource同样是需要先引入依赖
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        KafkaSource<String> source = KafkaSource.<String>builder()
                .setBootstrapServers("hadoop102:9092,hadoop103:9092,hadoop104:9092")
                .setTopics("flink-learning")
                .setGroupId("nepu")
                .setValueOnlyDeserializer(new SimpleStringSchema())
                .setStartingOffsets(OffsetsInitializer.latest())
                .build();

        DataStreamSource<String> kafkaSource = env.fromSource(source, WatermarkStrategy.noWatermarks(), "kafkaSource");

        kafkaSource.shuffle();
        kafkaSource.rebalance();
        kafkaSource.rescale();
        kafkaSource.broadcast();

        kafkaSource.print();

        env.execute();


    }
}
